<template>
  <div class="album-row">
     <div class="flex-sbt">
         <span>按时间发布</span>
         <!-- <v-icon>

         </v-icon> -->
         <span>列表</span>
         
     </div>

     <ul class="album-list">

        <li class="album-item" v-for="(item,i) in albums" :key="i"
            @click="$emit('detail-click', item, 'album')"
        >
            <div class="album-cover"> 
                <img :src="item.picUrl +'?imageView&thumbnail=100y100&quality=100&tostatic=0'" />
            </div>
            <div class="album-info">
                <h5>{{item.name}} <span class="album-alias" v-if="Array.isArray(item.alias) && item.alias.length > 0">({{item.alias.join(',')}})</span></h5>
                <span>{{dformatPublishTime(item.publishTime)}}  <span style="margin-left: 10px">{{item.size}}首</span></span>
            </div>
        </li>
     </ul>

  </div>
</template>

<script>

import api from '@/api';
import { dformatTimetemp } from '@/utils/utils';

export default {
    props: ['data'],
    watch: {
        data(n){
            if(n && n.artist){
                this.getAblumsBySingerId(n.artist.id)
            }
        }   
    },

    data(){
        return {
            albums: []
        }
    },

    methods: {
        getAblumsBySingerId(id) {

            console.log(id);
            if(!id) return;

            api.getAblumsBySingerId(id).then(res => {
                console.log(res);

                this.albums = res.data.hotAlbums;

            })
        },

        dformatPublishTime(timetemp){
            return dformatTimetemp(timetemp)
        }
    },

    created(){
        if(this.data.artist){
          this.getAblumsBySingerId(this.data.artist.id);
        }
    },

    mounted(){

        console.log('album' , this.data)
    }
}
</script>

<style lang="scss" scoped>
    @import '@/assets/styles/global.scss';
    .album-row {
        padding: px2rem(10);
        background-color: #fff;
        .flex-sbt {
            @include spaceBetween;
            * {
                @include defaultTitle;
            }
        }

        .album-list {

            .album-item {
                @include defaultFontSize;
                @include top;
                height: px2rem(60);
                margin: px2rem(20) 0;
                .album-cover {
                    flex-shrink: px2rem(60);
                    width: px2rem(60);
                    position: relative;
                    margin-right: px2rem(10);
                    &::after {
                        content: '';
                        position: absolute;
                        left: 50%;
                        transform: translateX(-50%);
                        z-index: 1;
                        width: px2rem(50);
                        height: px2rem(50);
                        border-radius: 50%;
                        background-color: #222;
                    }
                    img {
                        position: absolute;
                        z-index: 2;
                        width: px2rem(60);
                        height: px2rem(60);
                        border-radius: px2rem(8);
                        border: 1px solid #ccc;
                        top: px2rem(6);
                        left: 0;
                    }
                }
                .album-info {
                    height: 100%;
                    flex: 1;
                    display: flex;
                    flex-direction: column;
                    justify-content: center;
                    align-items: flex-start;

                    h5 {
                        @include defaultTitle;
                        color: #333;

                        .album-alias {
                            color: #606060;
                        }
                    }

                    span {
                        @include defaultFontSize;
                        color: #606060;
                    }
                }
            }
        }
    }
</style>